

#include "GameType.h"
#include "Globals.h"
void GameType::Type(int type,Engine* Members){
mGameType=type;
GetArrays(Members);

}
unsigned long GameType::GetConnection(){

	if(isZM()){
		return 0x05EEB8;
	}else if(isMF()){
		return 0x6945c;
	}else{
		return 0;
	}
}
void GameType::GetArrays(Engine* EnginePnt){
	EnginePnt->OpenFile();
	FILE* fp=EnginePnt->oFP();
	if(isZM()){
		int i=0,ii=0;;
		u32 myoffset=0x833DFDC;

		memset(EnginePnt->Members.RoomTilesets,0,0x500);
		
		
		fseek(fp, myoffset-0x8000000,SEEK_SET);//Tileset
		ii=GetLastError();
		for( i=0;i<0x50;i++){
			fread(&EnginePnt->Members.RoomTilesets[i].gTiles,4,1,fp);
			
			fread(&EnginePnt->Members.RoomTilesets[i].pTiles,4,1,fp);
			fread(&EnginePnt->Members.RoomTilesets[i].gBackground,4,1,fp);
			fread(&EnginePnt->Members.RoomTilesets[i].TSAMap,4,1,fp);
			fread(&EnginePnt->Members.RoomTilesets[i].EffectSet,4,1,fp);  
		}
		
		fseek(fp,0x75FD28,SEEK_SET);
		for( i = 0; i < 0xB;i++) fread(&EnginePnt->Members.gScrolls[i],4,1,fp);
		fseek(fp, 0x75FAC4,SEEK_SET);
		fread(RoomOffsets,sizeof(long),7,fp);
		fseek(fp,0x75FAA8,SEEK_SET);
		fread(DoorOffsets,sizeof(long),7,fp);
	}else{
		int i=0;

		fseek(fp,0x2E4A50,SEEK_SET);
		fread(&MFSprSize,4,0xC0,fp);
		fseek(fp, 0x3BF888,SEEK_SET);//Tileset
		for(i=0;i<0x70;i++){
			fread(&EnginePnt->Members.RoomTilesets[i].gTiles,sizeof(long),1,fp);
			fread(&EnginePnt->Members.RoomTilesets[i].pTiles,sizeof(long),1,fp);
			fread(&EnginePnt->Members.RoomTilesets[i].gBackground,sizeof(long),1,fp);
			fread(&EnginePnt->Members.RoomTilesets[i].TSAMap,sizeof(long),1,fp);
			fread(&EnginePnt->Members.RoomTilesets[i].EffectSet,sizeof(long),1,fp);  
		}
		
		fseek(fp,0x79BB08,SEEK_SET);
		for(i = 0; i < 0xB;i++) fread(&EnginePnt->Members.gScrolls[i],4,1,fp);
		fseek(fp, 0x79B8BC,SEEK_SET);
		fread(RoomOffsets,4,10,fp);
		fseek(fp,0x79B894,SEEK_SET);
		fread(DoorOffsets,4,10,fp);
		fseek(fp,0x3e419c,SEEK_SET);
		fread(&VRAM.RAM[0x900],1,0x36E0,fp);
		fseek(fp,0x58b466,SEEK_SET);
		fread(&GBASprPal[0x40],1,0x14,fp);
		fseek(fp,0x3E40F2,SEEK_SET);
		fread(&GBASprPal[0x56],1,0x3E,fp);
		
	}
}
void GameType::GetCRETileset(Engine* EnginePnt, unsigned char* pal, unsigned char* gfx,unsigned char Area){
	EnginePnt->OpenFile();
		FILE* fp=EnginePnt->oFP();
	if(isZM()){
		fseek(fp,0x31C72E,SEEK_SET);
		fread(&EnginePnt->GBAPal[1],sizeof(short),15,fp);
		fseek(fp,0x3ED51C,SEEK_SET);
		fread(&EnginePnt->GBAPal[16],sizeof(short),16,fp);
		//fseek(fp,0x5d940c + Area==6? 0x1000:0, SEEK_SET);
		fseek(fp,0x5d940c, SEEK_SET);
	}else{

		
		EnginePnt->GBAPal[0] = 0;
		fseek(fp,0x40805E,SEEK_SET);
		fread(&EnginePnt->GBAPal[1],2,47,fp);
		fseek(fp,0x3F28C8,SEEK_SET);	
		
	}
	fread(&EnginePnt->Members.fGbuf[0x800],1,4098,fp);
}

